set more off
capture log close

//  program:    AnanatEtAl_mobility
//  task:		Run Regressions predicting population counts and shares as a function of job losses 

//change working directory to point to the file with the data
cd *** Fill in path name here ***

//create log file
log using AnanatEtAl_mobility, replace text

//Load the ACS Population data
use AnanatEtAl_ACS_data, clear

//set the panel variables
xtset stateno year

/* CREATE YEAR AND STATE INDICATORS */
sort stateno year
by stateno: gen t = _n
tab year, gen(yrd)
quietly: tab stateno, gen(stated)
sort stateno year

//#1
//Job Losses as Predictor of the Share of Total State Population for Select Demographic Supgroups

ivregress 2sls share_black yrd* stated* (seppctyrlag = ticpctyrlag), vce(cluster stateno) first
	est store share_black
	outreg2 [share_black] using AnanatEtAl_pop_mobility, drop(yrd* stated*) excel dec(3) replace

foreach var of varlist share_white share_hispan share_minor share_elderly share_lesshs share_hsgrad share_somecoll share_collgrad share_poor{
	ivregress 2sls `var' yrd* stated* (seppctyrlag = ticpctyrlag), vce(cluster stateno) first
	est store `var'
	outreg2 [`var'] using AnanatEtAl_pop_mobility, drop(yrd* stated*) excel dec(3)
}

//#2
//Job Losses as Predictor of the Level of 13-14 year olds and 14-18 year olds in a state and the subgroup shares of the teen population for select demographic characteristics
ivregress 2sls age1314_total yrd* stated* (seppctyrlag = ticpctyrlag), vce(cluster stateno) first
	est store age1314_total
	outreg2 [age1314_total] using AnanatEtAl_teen_mobility, drop(yrd* stated*) excel dec(3) replace

foreach var of varlist age1418_total share_age* {
	ivregress 2sls `var' yrd* stated* (seppctyrlag = ticpctyrlag), vce(cluster stateno) first
	est store `var'
	outreg2 [`var'] using AnanatEtAl_teen_mobility, drop(yrd* stated*) excel dec(3)
}

clear all

//#3
//Job losses as predictor of subgroup shares of 8th grade math test takers 
//load the test score data
use AnanatEtAl_test_score_data, clear

//set the panel variables
xtset stateno year

//run the regressions
foreach n in male white black hisp {
ivregress 2sls `n'_percentage yrd* stated* (seppctyrlag = ticpctyrlag), vce(cluster stateno) first
est store `n'
}
outreg2 [male white black hisp] using AnanatEtAl_test_taker_mobility, drop(yrd* stated*) excel replace dec(3)

clear all
log close

